package com.NHL.single.extra
{
	import com.NHL.single.AmfCallPHP;
	import com.NHL.single.GlobalTime;
	
	import flash.net.Responder;
	
	public class GResponder extends Responder
	{
		
		public function get sn():Number
		{
			return _sn;
		}

		public function set sn(value:Number):void
		{
			_sn = value;
		}

		public function get method():String
		{
			return _method;
		}
		
		public function set method(value:String):void
		{
			_method = value;
		}
		
		public function get resultFun():Function
		{
			return _resultFun;
		}
		
		public function set resultFun(value:Function):void
		{
			_resultFun = value;
		}
		
		public function set statusFun(value:Function):void
		{
			_statusFun = value;
		}
		
		private var _sn:Number;
		
		private var _method:String;
		
		private var _resultFun:Function;
		
		public var canceled:Boolean;
		
		private var _statusFun:Function;
		
		public var params:Object;
		public function GResponder(result:Function=null, status:Function=null)
		{
			this._resultFun = result;
			this._statusFun = status;
			super(resultHandle, statusHandle);
		}
		
		private function resultHandle(data:Object):void
		{
			updateServerTime(data);
			if(canceled)
				return;
			else
			{
				
				if(_resultFun!=null&&data.hasOwnProperty("data"))
				{
					_resultFun(params,data.data);
				}
				if(data.hasOwnProperty("callBack"))
				{					
					AmfCallBack.getInstance().Done(data.callBack);	
				}
			}
			
		}
		
		private function statusHandle(data:Object):void
		{
			if(canceled)
				return;
			else
			{
				if(_statusFun!=null)
					_statusFun(params,data.faultString);
				else
				{
					trace();
				}
			}
		}
		
		private function updateServerTime(data:Object):void
		{
			if(data.hasOwnProperty("serverTime"))
			{
				var amfcaller:GlobalTime = GlobalTime.getInstance();
				amfcaller.severTime = data.severTime;
				delete data["serverTime"];
				
			}
		}
		
	}
}